home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / AOCE Sample Code / Interprogram Messaging Manager / IPM MessageBoard / GetAttribute.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  3.1 KB  |  107 lines  |  [TEXT/KAHL]

  1. #include "GetAttribute.h"
  2.  
  3.  
  4. OSErr GetAttributeFromRID (RecordIDPtr rid, const AttributeTypePtr attrType,
  5.     AttributePtr *theAttribute, AuthIdentity identity)
  6. {
  7.     OSErr            err;
  8.     RecordIDPtr        recordList[1];
  9.     AttributeTypePtr    attTypeList[1];
  10.     DirParamBlock        pb;
  11.     
  12.  
  13.     recordList[0] = rid;
  14.     attTypeList[0] = attrType;
  15.  
  16.     pb.lookupGetPB.ioCompletion = nil;
  17.     pb.lookupGetPB.serverHint.aNet = 0;
  18.     pb.lookupGetPB.serverHint.aNode = 0;
  19.     pb.lookupGetPB.serverHint.aSocket = 0;
  20.     pb.lookupGetPB.dsRefNum = 0;
  21.     pb.lookupGetPB.identity = identity;
  22.     pb.lookupGetPB.clientData = 0L;
  23.     pb.lookupGetPB.aRecordList = recordList;
  24.     pb.lookupGetPB.attrTypeList = attTypeList;
  25.     pb.lookupGetPB.recordIDCount = 1;
  26.     pb.lookupGetPB.attrTypeCount = 1;
  27.     pb.lookupGetPB.includeStartingPoint = TRUE;
  28.     pb.lookupGetPB.getBuffer = NewPtr(kBufSize);
  29.     if ((err = MemError()) != noErr)
  30.         return err;
  31.     pb.lookupGetPB.getBufferSize = kBufSize;
  32.     pb.lookupGetPB.startingRecordIndex = 1;
  33.     pb.lookupGetPB.startingAttrTypeIndex = 1;
  34.     pb.lookupGetPB.startingAttribute.cid.source = 0L;
  35.     pb.lookupGetPB.startingAttribute.cid.seq = 0L;
  36.  
  37.  
  38.     if ((err = DirLookupGet (&pb, FALSE)) == noErr)
  39.     {
  40.         *theAttribute = (AttributePtr) -1;
  41.         pb.lookupParsePB.ioCompletion = nil;
  42.         pb.lookupParsePB.serverHint.aNet = 0;
  43.         pb.lookupParsePB.serverHint.aNode = 0;
  44.         pb.lookupParsePB.serverHint.aSocket = 0;
  45.         pb.lookupParsePB.dsRefNum = 0;
  46.         pb.lookupParsePB.identity = identity;
  47.         pb.lookupParsePB.clientData = (long) theAttribute;
  48.         pb.lookupParsePB.aRecordList = recordList;
  49.         pb.lookupParsePB.attrTypeList = attTypeList;
  50.         pb.lookupParsePB.eachRecordID = myForEachLookupRecordID;
  51.         pb.lookupParsePB.eachAttrType = myForEachAttrTypeLookup;
  52.         pb.lookupParsePB.eachAttrValue = myForEachAttrValue;
  53.         pb.lookupParsePB.recordIDCount = 1;
  54.         pb.lookupParsePB.attrTypeCount = 1;
  55.         pb.lookupParsePB.getBuffer = pb.lookupGetPB.getBuffer;
  56.         pb.lookupParsePB.getBufferSize = pb.lookupGetPB.getBufferSize;
  57.         err = DirLookupParse (&pb, FALSE);
  58.         if (err == noErr && *theAttribute == nil)
  59.             err = memFullErr;
  60.  
  61.         if (*theAttribute == (AttributePtr) -1)
  62.             {
  63.             err = kOCENoSuchAttributeType;
  64.             *theAttribute = nil;
  65.             }
  66.     }
  67.     
  68.     if (pb.lookupGetPB.getBuffer != nil)
  69.         DisposePtr (pb.lookupGetPB.getBuffer);
  70.  
  71.     return (err);
  72. }
  73.  
  74. static pascal Boolean myForEachLookupRecordID (long clientData, const RecordID *recordID)
  75. {
  76. #pragma unused (clientData,recordID)
  77.  
  78.     return (FALSE);
  79. }
  80.  
  81. static pascal Boolean myForEachAttrTypeLookup (long clientData,
  82.     const AttributeType *attrType, AccessMask myAttrAccMask)
  83. {
  84. #pragma unused (clientData,attrType,myAttrAccMask)
  85.  
  86.     return (FALSE);
  87. }
  88.  
  89. static pascal Boolean myForEachAttrValue (long clientData, const Attribute *attribute)
  90. {
  91.     AttributePtr    *theAttribute;
  92.  
  93.     theAttribute = (AttributePtr *) clientData;
  94.     if ((*theAttribute = (AttributePtr)NewPtr (sizeof (Attribute))) != nil)
  95.     {
  96.         BlockMove((Ptr) attribute, *theAttribute,sizeof (Attribute));
  97.         if (((**theAttribute).value.bytes = NewPtr ((*attribute).value.dataLength)) != nil)
  98.             BlockMove((*attribute).value.bytes,(**theAttribute).value.bytes,(*attribute).value.dataLength);
  99.         else
  100.         {
  101.             DisposePtr ((Ptr)*theAttribute);
  102.             *theAttribute = nil;
  103.         }
  104.     }
  105.     
  106.     return (TRUE);
  107. }